﻿using System;
using System.Globalization;


namespace FireBus.Contracts
{
	[Serializable]
	public class RequestMetadata
	{
		private readonly TypeName _Request;

		private readonly TypeName _Response;


		public TypeName Request
		{
			get { return _Request; }
		}

		public TypeName Response
		{
			get { return _Response; }
		}


		public RequestMetadata(TypeName request, TypeName response)
		{
			if (request == null)
			{
				throw new ArgumentNullException("request");
			}
			if (response == null)
			{
				throw new ArgumentNullException("response");
			}
			_Request = request;
			_Response = response;
		}


		public override String ToString()
		{
			return String.Format(
				CultureInfo.InvariantCulture,
				"{1} <- {0}", _Request, _Response);
		}

		public override Int32 GetHashCode()
		{
			return
				_Request.GetHashCode() ^
				_Response.GetHashCode();
		}

		public override Boolean Equals(Object obj)
		{
			return Equals(obj as RequestMetadata);
		}

		public Boolean Equals(RequestMetadata request)
		{
			if (request == null)
			{
				return false;
			}
			if (ReferenceEquals(this, request))
			{
				return true;
			}
			return
				_Request.Equals(request._Request) &&
				_Response.Equals(request._Response);
		}
	}
}
